import math
import time
# import numpy as np
from typing import List


def word_term(a:int, r:int, p:int) -> float:
    """
    :param a: appear
    :param r: recommend
    :param p: amount
    :return: ( a * p ) / r
    """
    if r > 0:
        return (a*p)/r
    elif a > 0:
        return float('inf')
    return float('inf')

def random_recommend(wt:List[float]) -> float:
    """
    :param wt: list(word_term)
    :return score: e ^ ( -1 / Σ wti ) 
    """
    sum = 0
    for i in wt:
        if i == float('inf'):
            return float(1)
        sum += i
    if sum == 0:
        return float(0)
    return math.exp(-1/sum)

def get_res_by_probability(prob) -> int:
    """
    :param k: len(recommender)
    :return: 
    """
    if prob >= 1:
        return 1
    else:
        # np.random.seed(int(time.time()))
        # x = np.random.binomial(1, prob)
        # return x
        return 0
